package com.content;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Test {

    public static void main(String[] args) {
        int i = 1232323986;
        System.out.println(i%100/10);
        
        Test t = new Test();
        int[] ary = new int[]{11,22,33,44,55};
        int[] ary1 = new int[]{111,222,333};
        System.arraycopy(ary,1,ary,3,2);
        System.out.println(Arrays.toString(ary));

    }

    /**
     * 快速排序数组划分
     * @param ary
     * @param low
     * @param high
     * @return
     */
    public int divArry(int[] ary,int low,int high){
        int biaoBingFlag = ary[low];
        //下面是个重复的动作，直到i=j的时候退出，此时将标兵值放上，得到区分区间
        while(low < high){
            //从高位向低位寻找比标兵小的值，找到后高位给低位
            while (low < high && ary[high] >= biaoBingFlag){
                high --;
            }
            ary[low] = ary[high];
            //从低位向高位寻找比标兵大的值，找到后低位给高位
            while (low < high && ary[low] <= biaoBingFlag){
                low ++;
            }
            ary[high] = ary[low];
        }
        // 直到i=j的时候退出，此时将标兵值放上，得到区分区间
        ary[low] = biaoBingFlag;
        return low;
    }



    public void quickSort3(int[] arr,int low,int high){
        if (low < high){
            int divFlag = divFlag(arr,low,high);
            quickSort3(arr,0,divFlag -1);
            quickSort3(arr,divFlag + 1,divFlag -1);
        }
    }
    //快速排序
    public int divFlag(int[] arr,int low,int high){
        // 基准数据
        int tmp = arr[low];
        while (low < high) {
            // 当队尾的元素大于等于基准数据时,向前挪动high指针
            while (low < high && arr[high] >= tmp) {
                high--;
            }
            // 如果队尾元素小于tmp了,需要将其赋值给low
            arr[low] = arr[high];
            // 当队首元素小于等于tmp时,向前挪动low指针
            while (low < high && arr[low] <= tmp) {
                low++;
            }
            // 当队首元素大于tmp时,需要将其赋值给high
            arr[high] = arr[low];

        }
        // 跳出循环时low和high相等,此时的low或high就是tmp的正确索引位置
        // 由原理部分可以很清楚的知道low位置的值并不是tmp,所以需要将tmp赋值给arr[low]
        arr[low] = tmp;
        System.out.println(Arrays.toString(arr));
        return low;
    }
    //插入排序
    public void insertSort3(){
        int[] ary = new int[]{100,0,1,2,9,8,7};
        int tempUnSeq;//待排序元素
        for (int i = 1; i < ary.length; i++) {
            tempUnSeq = ary[i];
            //从当前下标开始向前寻找一个比自己小的值位置索引
            int seq = i;
            while (seq >0 && ary[seq -1]>tempUnSeq){
                ary[seq] = ary[seq -1];
                seq --;
            }
            //得到这个插入位置后插入数据
            ary[seq] = tempUnSeq;
        }
        System.out.println(Arrays.toString(ary));
    }

    public void bubbleSort2(){
        int[] soruce = new int[]{9,8,7,6};
        for (int j = 0; j < soruce.length - 1; j++) {
            for (int i = 1; i < soruce.length - j; i++) {
                if(soruce[i -1] > soruce[i]){
                    int temp = soruce[i];
                    soruce[i] = soruce[i -1];
                    soruce[i - 1] = temp;
                }
            }
        }

        System.out.println(Arrays.toString(soruce));
    }
    //快速排序
    public void insertSort2(){
        int[] soruce = new int[]{9,8,7,6,5,4,3,2,1};

        for (int i = 0; i < soruce.length; i++) {
            int tempi = soruce[i];
            int j = i;
            while (j > 0){
                if(tempi < soruce[j-1]){
                    soruce[j] = soruce[--j];
                }else{
                    j--;
                }
            }
            soruce[j] = tempi;
        }
        System.out.println(Arrays.toString(soruce));
    }
    //快排入口
    public void quickSortTest(){
        int[] soruce = new int[]{5,1,6,2,7,3,8};
        quickSort(soruce,0,soruce.length - 1);
        System.out.println(Arrays.toString(soruce));
    }
    public int adjustArray(int[] soruce,int l,int r){
            int flagVal = soruce[l];
            //定义下标
            //一直循环判断值大小
            while(l < r){
                //跳过所有比标兵大的值
                while(soruce[r] > flagVal){
                    if(l >= r){
                        break;
                    }
                    r --;
                }
                if(soruce[r] < soruce[l]){
                    soruce[l] = soruce[r];
                    l ++;
                }
                while (soruce[l] < soruce[r]){
                    if(l >= r){
                        break;
                    }
                    l++;
                }
                if(soruce[l] > soruce[r]){
                    soruce[r] = soruce[l];
                    r --;
                }
            }
            //分界点
            soruce[l] = flagVal;
            //输出排序结果
//        System.out.println(Arrays.toString(soruce));
//        System.out.println("divFlag:"+l);
        return l;
    }
    public void quickSort(int[] source,int l,int r){
        if(l < r){
            int divFlag = adjustArray(source,l,r);
//            if(divFlag  > 0){
                quickSort(source,l,divFlag-1);
//            }
            quickSort(source,divFlag + 1,r);
        }
    }

    public void insertSort(){
        int[] soruce = new int[]{7,3,5,0,2,6};
        int i,j;
        for (i = 0; i < soruce.length; i++) {
            int tempi = soruce[i];
            for (j = i;j>=1 && tempi > soruce[j - 1]; j--) {
                soruce[j] = soruce[j - 1];
            }
            soruce[j] = tempi;
        }
        for (int x:soruce) {
            System.out.println(x);
        }
    }

    /**
     * 水仙花
     */
    public void shiXianHua(){
         /* int i = 153;
        int ge = i % 10;
        int sh = i % 100 /10;
        int bai = i  /100;
        System.out.println(ge);
        System.out.println(sh);
        System.out.println(bai);*/
        for (int i = 100; i < 1000; i++) {
            int ge = i % 10;
            int sh = i % 100 /10;
            int bai = i  /100;
            if((ge*ge*ge + sh*sh*sh + bai*bai*bai) == i){
                System.out.println(i);
            }
        }
    }
    public void testCompare(){
        Map map = new TreeMap(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.compareTo(o1);
            }
        });
        map.put("20200115c", "1");
        map.put("20200116a", "1");
        map.put("20200115bb", "1");
        map.put("20200117b", "1");
        Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> entry = it.next();
            System.out.println(entry.getKey() + " : " + entry.getValue());
        }
    }
    public static void getCMonth(){
        SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy/MM");

        String dyear="2020"; String dmouth="2";

        Calendar rightNow = Calendar.getInstance();

        try{

            rightNow.setTime(simpleDate.parse(dyear+"/"+dmouth));

        }catch(ParseException e){

            e.printStackTrace();

        }

        int days = rightNow.getActualMaximum(Calendar.DAY_OF_MONTH);//根据年月 获取月份天数
        System.out.println(days);
    }
    public static  void testC(){
        //获取东八区时间
        Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"));
        //获取年
        int year = c.get(Calendar.YEAR);
        //获取月份，会少一天。所以+1
        int month = c.get(Calendar.MONTH) + 1;
        //获取当前天数
        int day = c.get(Calendar.DAY_OF_MONTH);

        c.add(Calendar.YEAR,5);
        c.add(Calendar.DATE, +10);
        //获取当前小时
        int h= c.get(Calendar.HOUR_OF_DAY);
        //获取当前分钟
        int m = c.get(Calendar.MINUTE);
        //获取当前秒
        int se = c.get(Calendar.SECOND);

        SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //格式化时间格式
        String Now = s.format(c.getTime());
        //获得当前日期     format（Obj）：格式化一个对象以生成一个字符串。
        System.out.println("当前时间:" + year + "-" + month + "-"+ day + " "+h+":" + m +":" + se);
        System.out.println("当前日期Now:" + Now);
    }
    /**
     * 杨辉三角
     */
    public void testTran(){
        int[][] xy = new int[100][100];
        for (int i = 0; i < xy.length; i++) {
            for (int j = 0; j <= i; j++) {
                if(i == j || j == 0){
                    xy[i][j] = 1;
                }else{
                    xy[i][j] = xy[i-1][j-1] + xy[i-1][j];
                }
                System.out.print(xy[i][j] + " ");
            }
            System.out.println();
        }
    }
    //乘法
    public void chengFa(){
        int[][] chen = new int[9][9];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j <= i; j++) {
                chen[i][j] = (i+1)*(j+1);
                System.out.print((i+1)+"*"+(j+1)+"="+chen[i][j] + " ");
            }
            System.out.println();
        }
    }
}
